<?php

namespace App\Http\Requests;

use App\Util\Result;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;

class BannerRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'img_url'  => 'required',
            'http_url' => 'bail|required|active_url',
        ];
    }

    public function messages()
    {
        return [
            'img_url.required'  => '请上传图片',
            'http_url.required' => '请输入图片连接',
            'http_url.active_url'  => '您输入的网址有误，请检查',
        ];
    }


    protected function formatErrors(Validator $validator)
    {
        return Result::failure( $validator->errors()->first() )->getResult();
    }

}
